package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-rule")
@Api("报警规则")
public class AlertRuleController extends BaseController {
    @Autowired
    private AlertRuleService alertRuleService;

    @PostMapping("/create")
    @ApiOperation("新增报警规则")
    public ResponseResult create(@RequestBody AlertRuleDto alertRuleDto){
        alertRuleService.create(alertRuleDto);
        return ResponseResult.success();
    }

    @GetMapping("/get-page")
    @ApiOperation("查看警告")
    public ResponseResult<PageResponse<AlertRuleVo>> getPage( Integer pageNum,
                                                              Integer pageSize,
                                                              String alertRuleNmae,
                                                              String functionName,
                                                              String productKey){
        PageResponse<AlertRuleVo> response = alertRuleService.getPage(pageNum,pageSize,alertRuleNmae,functionName,productKey);
        return ResponseResult.success(response);
    }

    @GetMapping("read/{id}")
    @ApiOperation("获取单个警告")
    public ResponseResult<AlertRuleVo> getRead(@PathVariable Integer id){
        AlertRuleVo alertRuleVo = alertRuleService.getRead(id);
        return ResponseResult.success(alertRuleVo);
    }

    @PutMapping("/update/{id}")
    @ApiOperation("修改警告规则")
    public ResponseResult update(@RequestBody AlertRuleDto alertRuleDto){
        alertRuleService.update(alertRuleDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除警告规则")
    public ResponseResult delete(@PathVariable Integer id){
        alertRuleService.delete(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用警告规则")
    public ResponseResult updateStatus(@PathVariable Integer id,@PathVariable Integer status){
        alertRuleService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
